import java.util.Arrays;

public class Solution1846 {
    public int maximumElementAfterDecrementingAndRearranging(int[] arr) {
        Arrays.sort(arr);
        arr[0]=1;
        for (int i=1;i<arr.length;i++){
            arr[i]=Math.min(arr[i],arr[i-1]+1);
        }
        return arr[arr.length-1];
    }

    public static void main(String[] args) {
        System.out.println(new Solution1846().maximumElementAfterDecrementingAndRearranging(new int[]{2,2,1,2,1}));
    }
}
